package com.ztom.context.support

import com.ztom.beans.factory.ConfigurableListableBeanFactory
import com.ztom.beans.factory.DefaultListableBeanFactory

/**
 * @author ZhangTao
 */
abstract class AbstractRefreshableApplicationContext : AbstractApplicationContext() {

    /**
     * 组合了一个 beanFactory
     */
    private lateinit var beanFactory: DefaultListableBeanFactory

    override fun refreshBeanFactory() {
        val beanFactory = createBeanFactory()
        loadBeanDefinitions(beanFactory)
        this.beanFactory = beanFactory
    }

    private fun createBeanFactory(): DefaultListableBeanFactory {
        return DefaultListableBeanFactory()
    }

    protected abstract fun loadBeanDefinitions(beanFactory: DefaultListableBeanFactory)

    override fun getBeanFactory(): ConfigurableListableBeanFactory {
        return beanFactory
    }
}